package cn.com.chinahitech.bjmarket.user.service.impl;

import cn.com.chinahitech.bjmarket.user.entity.User;
import cn.com.chinahitech.bjmarket.user.mapper.UserMapper;
import cn.com.chinahitech.bjmarket.user.service.IUserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhufu
 * @since 2020-07-07
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<User> getUserByName(String name) {
        List<User> userList =null;
        //1)创建QueryWrapper对象
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.like("name",name);
        //2)执行查询
        userList = userMapper.selectList(wrapper);
        return userList;
    }

    @Override
    public User getUeserByUid(String uid) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("userid",uid);
        User user=userMapper.selectOne(wrapper);
        return user;
    }

    @Override
    public IPage<User> getUserAtPage(int p, int size,String name) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.like("name",name);
        Page<User> page = new Page<>(p, size);
        IPage<User> userIPage = getBaseMapper().selectPage(page, wrapper);
        return userIPage;
    }

    @Override
    public void updatePhone(String phoneNumber, String uid) {
        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        wrapper.eq("userid",uid);

        User user = new User();
        user.setPhoneNumber(phoneNumber);

        userMapper.update(user,wrapper);
    }
}
